﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Forget.Data;

namespace Forget.HRBLL.Model
{
    public partial class Dict
    {
        private static readonly string ADDDICT = "HR_AddDict";
        private static readonly string EDITDICT = "";
        private static readonly string DELDICT = "";

        #region properties
        [DataParam(32, System.Data.SqlDbType.Int)]
        public int? DictID { get; set; }

        [DataParam(20, System.Data.SqlDbType.NVarChar)]
        public string Name { get; set; }

        [DataParam(32, System.Data.SqlDbType.Int)]
        public int? Type { get; set; }

        [DataParam(32, System.Data.SqlDbType.Int)]
        public int? Order { get; set; }
        #endregion

        public static bool AddDict(Dict dict)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(dict);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, ADDDICT, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.AddDict", ex.Message, ex.StackTrace);
            }
            return false;
        }

        public static bool EditDict(Dict dict)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(dict);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, EDITDICT, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.EditDict", ex.Message, ex.StackTrace);
            }
            return false;
        }

        public static bool DelDict(Dict dict)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(dict);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, DELDICT, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.DelDict", ex.Message, ex.StackTrace);
            }
            return false;
        }
    }
}
